import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/31 8:52
 * @description 思路：二分查找
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public int specialArray(int[] nums) {
        Arrays.sort(nums);
        int left = 1, right = 1000;
        int n = nums.length;
        while (left < right) {
            int mid = (left + right) / 2;
            if(mid > nums[n - 1]) {
                // 排序后右边为最大的数
                right = mid - 1;
            }else if (mid < nums[0]) {
                if (mid == n) {
                    return mid;
                }else if (mid > n) {
                    right = mid - 1;
                }else {
                    left = mid + 1;
                }
            }
        }
        return -1;
    }
}
